<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link type="text/css" rel="stylesheet" href="/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="/css/ico.css" />
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/clipboard.min.js"></script>
<script type="text/javascript" src="/js/util.js"></script>
<title>Z盘</title>
<style type="text/css">
#title {
	font-size: 2em;
	margin-left: 1%;
	padding-top: 0.5em;
}

.col-left {
	float: left;
	width: 70%;
	margin-left: 1%;
}

.col-right {
	float: right;
	width: 27%;
	margin: 0 1%;
}

#current-location {
	line-height: 3em;
}

#current-location2 {
	line-height: 3em;
	margin-left: 1%;
}

#current-page {
	float: right;
	display: inline-block;
	width: 11em;
	text-align: right;
	line-height: 3em;
}

#current-operation {
	line-height: 3em;
	display: inline-block;
}

#operation {
	float: right;
	height: 3em;
}

#preview-default {
	border: solid 1px;
	height: 20em;
	text-align: center;
}

#preview-img {
	border: solid 1px;
	display: none;
	min-height: 20em;
}

#preview-img img {
	max-width: 100%;
}

#preview-text {
	display: none;
	min-height: 20em;
	max-height: 40em;
	white-space: pre-wrap;
	word-wrap: break-word;
}

.bigImg {
	max-width: 100%;
	max-height: 100%;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
}

.bigImgShade {
	width: 100%;
	height: 100%;
	position: fixed;
	background: rgba(0, 0, 0, 0.4);
	z-index: 1000;
	top: 0;
	left: 0;
}

.other {
	opacity: 0;
}

#fileList tr:hover .other {
	opacity: 1;
}

.text {
	text-align: right;
	width: 6em;
	padding: 0.5em;
}

.input {
	padding: 0.5em 0 0 0;
}

.prompt {
	color: red;
	padding-left: 0.5em;
}

.link {
	font-size: 0.8em;
	text-align: right;
}
</style>
<script>
	/* 自动加载 */
	$(function() {
		init();
	});
	/* 初始化 */
	function init(folderId, folderName) {
		$("#editFile").hide();
		$("#showFile").show();
		$("#current-location").empty();
		if (folderId == undefined) {
			$("#title").text("我的文件");
			$("#newFolder").show();
			$("#current-location").append("当前位置：<a href='#' onClick='init()'>根目录</a>");
		} else {
			$("#title").text(folderName);
			$("#newFolder").hide();
			$("#current-location").append("当前位置：<a href='#' onClick='init()'>根目录</a> / "
				+ "<a href='#' onClick='init(\"" + folderId + "\",\"" + folderName + "\")'>" + folderName + "</a>");
		}
		$("#fileList").empty();
		/* 获取列表数据 */
		$.ajax({
			url : folderId == undefined ? "/user/file/info/" : "/user/folder/info/" + folderId,
			type : "post",
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				if (data.code == 0) {
					var list = data.data;
					if (list.length == 0) {
						showTips(null, "文件为空！", "success");
						return false;
					}
					var tr,
						id,
						name,
						suffix,
						timestamp,
						size,
						status,
						uuid,
						date,
						isfolder,
						isshare,
						issearch,
						islimit,
						pwd,
						clickFile;
					for (var i in list) {
						id = list[i].id;
						name = list[i].name;
						isfolder = list[i].isfolder;
						suffix = (isfolder == 1) ? "folder" : getFileSuffix(name);
						isshare = list[i].isshare,
						issearch = list[i].issearch,
						islimit = list[i].islimit,
						pwd = list[i].pwd;
						timestamp = list[i].timestamp;
						size = (isfolder == 1) ? "" : bytes2Size(list[i].length);
						status = (isshare == 1) ? (pwd.length == 0 ? "共享" : "密码") : "";
						uuid = list[i].uuid;
						date = time2Date(list[i].time);
						clickFile = (isfolder == 0) ?
							((folderId == undefined)
								? ("href='#' onClick='loadEditFile(\"" + id + "\")'")
								: ("href='#' onClick='loadEditFile(\"" + id + "\",\"" + folderId + "\",\"" + folderName + "\")'"))
							: ("href='#' onClick='init(\"" + id + "\",\"" + name + "\")'");
						clickDownload = (isfolder == 0)
							? ("href='/file/download/" + uuid + "' target='_blank'")
							: ("href='#' onClick='downloadFolder(\"" + uuid + "\")'");
						tr = "<tr id='" + id + "' name='" + name + "' timestamp='" + timestamp + "' uuid='" + uuid + "' isfolder='" + isfolder
							+ "' isshare='" + isshare + "' issearch='" + issearch + "' islimit='" + islimit + "' pwd='" + pwd
							+ "' onClick='" + "previewFile(" + id + ")" + "'>";
						tr += "<td><input type='checkbox' name='idcb' value='" + id + "'></td>";
						tr += "<td><a id='name" + id + "'" + clickFile + "><img class='ico ico-" + suffix + "'>" + name + "</a></td>";
						tr += "<td><span class='other'><a href='#' onClick='renameFile(" + id + ")'>重命名</a>"
							+ "&ensp;<a href='#' onClick='shareFile(" + id + ")'>分享</a>&ensp;<a " + clickDownload + ">下载</a></span></td>";
						tr += "<td>" + size + "</td>";
						tr += "<td id='status" + id + "'>" + status + "</td>";
						tr += "<td>" + date + "</td></tr>";
						$("#fileList").append(tr);
					}
				} else {
					showTips(null, data.msg);
				}
			},
			error : function(e) {
				showTips(null, "网络异常，请重试！", "warning");
			}
		})
		/* 全选checkbox添加监听事件 */
		$("#selectAll").click(function() {
			if ($(this).is(":checked")) {
				$("input[name='idcb']").prop("checked", true);
			} else {
				$("input[name='idcb']").prop("checked", false);
			}
		});
	}
	/* 获取选中的checkbox */
	function getCheckBoxValue() {
		var list = [];
		$.each($("input[name='idcb']:checked"), function() {
			list.push($(this).val());
		});
		return list;
	}
	/* 打包下载 */
	function downloadPackage() {
		var list = getCheckBoxValue();
		if (list.length == 0) {
			showTips(null, "没有文件被选择！");
			return false;
		}
		var uuids = [];
		for (var i in list) {
			if ($("#" + list[i]).attr("isfolder") == 0) {
				uuids.push($("#" + list[i]).attr("uuid"));
			}
		}
		if (uuids.length == 0) {
			showTips(null, "提示：文件夹不可打包下载！如需下载整个文件夹请点击文件夹右侧的下载按钮！");
			return false;
		}
		$.ajax({
			url : "/file/downloadPackage",
			type : "post",
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			data : JSON.stringify(uuids),
			success : function(data) {
				var text = data.data;
				if (data.code == 0) {
					var url = "/file/downloadPackage/" + text;
					showTips(null, "提示：文件夹不可打包下载！如需下载整个文件夹请点击文件夹右侧的下载按钮！<br><a href='" + url + "' target='_blank'>如果没有弹出下载页面，请点击此处下载。</a>", "success");
					window.open(url);
				} else if (data.code == 2003) { //文件过大
					showTips(null, "提示：文件过大，无法打包下载！<br>如果没有弹出页面，请复制本页内容。<br>" + text, "success");
					var newwindow = window.open(url);
					newwindow.document.write(text);
				} else {
					showTips(null, data.msg);
				}
			},
			error : function(e) {
				showTips(null, "网络异常，请重试！", "warning");
			}
		});
	}
	/* 下载文件夹 */
	function downloadFolder(uuid) {
		$.ajax({
			url : "/file/downloadFolder/" + uuid,
			type : "post",
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				var text = data.data;
				if (data.code == 0) {
					var url = "/file/downloadPackage/" + text;
					showTips(null, "<a href='" + url + "' target='_blank'>如果没有弹出下载页面，请点击此处下载。</a>", "success");
					window.open(url);
				} else if (data.code == 2003) { //文件过大
					showTips(null, "提示：文件过大，无法打包下载！<br>如果没有弹出页面，请复制本页内容。<br>" + text, "success");
					var newwindow = window.open(url);
					newwindow.document.write(text);
				} else {
					showTips(null, data.msg);
				}
			},
			error : function(e) {
				showTips(null, "网络异常，请重试！", "warning");
			}
		});
	}
	/* 删除文件 */
	function deleteFile() {
		list = getCheckBoxValue();
		if (list.length == 0) {
			showTips(null, "没有文件被选择！");
			return false;
		}
		$("#modal-button").unbind("click");
		$('#exampleModal').modal('show');
		$("#modal-title").text("删除");
		$("#deleteDiv").show();
		$("#newFolderDiv").hide();
		$("#renameDiv").hide();
		$("#shareDiv").hide();
		$("#modal-button").click(function() {
			deleteFileOk(list);
		});
	}
	function deleteFileOk(list) {
		$.ajax({
			url : "/user/file/delete",
			type : "post",
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			data : JSON.stringify(list),
			success : function(data) {
				if (data.code == 0) {
					var d = data.data;
					for (var i in d) {
						$("#" + d[i]).remove();
					}
					showTips(null, "文件已删除！", "success");
				} else {
					showTips(null, data.msg);
				}
			},
			error : function(e) {
				showTips(null, "网络异常，请重试！", "warning");
			}
		});
		$('#exampleModal').modal('hide');
	}
	/* 新建文件夹 */
	function newFolder() {
		$("#modal-button").unbind("click");
		$('#exampleModal').modal('show');
		$("#modal-title").text("新建文件夹");
		$("#newFolderName").val("");
		$("#deleteDiv").hide();
		$("#newFolderDiv").show();
		$("#renameDiv").hide();
		$("#shareDiv").hide();
		$("#modal-button").click(function() {
			newFolderOk();
		});
	}
	function newFolderOk() {
		var name = $("#newFolderName").val();
		if (name.length == 0) {
			showTips(null, "文件夹名不可为空！");
			return false;
		}
		$.ajax({
			url : "/user/file/newFolder/" + name,
			type : "post",
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				if (data.code == 0) {
					d = data.data;
					var tr = "<tr id='" + d.id + "' name='" + d.name + "' timestamp='" + d.timestamp + "' uuid='" + d.uuid
						+ "' isfolder='1' isshare='0' issearch='0' islimit='0' pwd='' onClick='" + "previewFile(" + d.id + ")" + "'>";
					tr += "<td><input type='checkbox' name='idcb' value='" + d.id + "'></td>";
					tr += "<td><a  id='name" + d.id + "' href='#' onClick='init(\"" + d.id + "\",\"" + d.name + "\")'><img class='ico ico-folder'>" + d.name + "</a></td>";
					tr += "<td><span class='other'><a href='#' onClick='renameFile(" + d.id + ")'>重命名</a>"
						+ "&ensp;<a href='#' onClick='shareFile(" + d.id + ")'>分享</a>"
						+ "&ensp;<a href='/file/download/" + d.uuid + "' target='_blank'>下载</a></span></td>";
					tr += "<td></td>";
					tr += "<td id='status" + d.id + "'>" + "</td>";
					tr += "<td>" + time2Date(d.time) + "</td></tr>";
					$("#fileList").prepend(tr);
					showTips(null, "文件已创建！", "success");
				} else {
					showTips(null, data.msg);
				}
			},
			error : function(e) {
				showTips(null, "网络异常，请重试！", "warning");
			}
		});
		$('#exampleModal').modal('hide');
	}
	/* 重命名文件 */
	function renameFile(id) {
		$("#modal-button").unbind("click");
		$("#newName").val($("#" + id).attr("name"));
		$('#exampleModal').modal('show');
		$("#modal-title").text("重命名");
		$("#deleteDiv").hide();
		$("#newFolderDiv").hide();
		$("#renameDiv").show();
		$("#shareDiv").hide();
		$("#modal-button").click(function() {
			renameFileOk(id);
		});
	}
	function renameFileOk(id) {
		var name = $("#newName").val();
		if (name.length == 0) {
			showTips(null, "文件名不可为空！");
			return false;
		}
		$.ajax({
			url : "/user/file/edit",
			type : "post",
			data : JSON.stringify({
				id : id,
				name : name,
			}),
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				if (data.code == 0) {
					$("#" + id).attr("name", name);
					$("#name" + id).empty();
					var suffix = $("#" + id).attr("isfolder") == 1 ? "folder" : getFileSuffix(name);
					$("#name" + id).append("<img class='ico ico-" + suffix + "'>" + name);
					showTips(null, "文件已重命名！", "success");
				} else {
					showTips(null, data.msg);
				}
			},
			error : function(e) {
				showTips(null, "网络异常，请重试！", "warning");
			}
		});
		$('#exampleModal').modal('hide');
	}
	/* 分享文件 */
	function shareFile(id) {
		$("#shareCb").unbind("click");
		$("#pwdCb").unbind("click");
		$("#modal-button").unbind("click");
		$("#copyLinkBtn").text("复制");
		$('#exampleModal').modal('show');
		$("#modal-title").text("分享");
		$("#deleteDiv").hide();
		$("#newFolderDiv").hide();
		$("#renameDiv").hide();
		var isshare = $("#" + id).attr("isshare");
		var issearch = $("#" + id).attr("issearch");
		var islimit = $("#" + id).attr("islimit");
		var pwd = $("#" + id).attr("pwd");
		var url = window.location.protocol + "//" + window.location.host + "/z/" + $("#" + id).attr("timestamp");
		var copyLinkText = "分享文件【" + $("#" + id).attr("name") + "】 下载地址: " + url;
		if (isshare == 1) {
			$("#shareCb").prop("checked", true);
			$(".shareOpen").show();
		} else {
			$("#shareCb").prop("checked", false);
			$(".shareOpen").hide();
		}
		if (issearch == 1) {
			$("#searchCb").prop("checked", true);
		} else {
			$("#searchCb").prop("checked", false);
		}
		if (islimit == 1) {
			$("#limitCb").prop("checked", true);
		} else {
			$("#limitCb").prop("checked", false);
		}
		if (pwd.length != 0) {
			$("#pwdCb").prop("checked", true);
			$("#pwdText").text(pwd);
			$("#linkText").text(url + " 密码: " + pwd);
			copyLink(copyLinkText + " 密码: " + pwd)
		} else {
			$("#pwdCb").prop("checked", false);
			$("#pwdText").text("");
			$("#linkText").text(url);
			copyLink(copyLinkText);
		}
		$("#shareCb").click(function() {
			if ($(this).is(":checked")) {
				$(".shareOpen").show();
			} else {
				$(".shareOpen").hide();
			}
		});
		$("#pwdCb").click(function() {
			if ($(this).is(":checked")) {
				pwd = randomFilePwd();
				$("#pwdText").text(pwd);
				$("#linkText").text(url + " 密码: " + pwd);
				copyLink(copyLinkText + " 密码: " + pwd)
			} else {
				$("#pwdText").text("");
				$("#linkText").text(url);
				copyLink(copyLinkText)
			}
		});
		$("#shareDiv").show();
		$("#modal-button").click(function() {
			var newShare = $("#shareCb").is(":checked") ? 1 : 0;
			var newSearch = $("#searchCb").is(":checked") ? 1 : 0;
			var newLimit = $("#limitCb").is(":checked") ? 1 : 0;
			var newPwd = $("#pwdCb").is(":checked") ? $("#pwdText").text() : "";
			shareFileOk(id, newShare, newSearch, newLimit, newPwd);
		});
	}
	/* 复制链接 */
	function copyLink(str) {
		$("#copyLinkBtn").click(function() {
			var clipboard = new ClipboardJS('#copyLinkBtn', {
				text : function() {
					return str;
				}
			});
			clipboard.on('success', function(e) {
				$("#copyLinkBtn").text("复制成功");
			});
			clipboard.on('error', function(e) {
				$("#copyLinkBtn").text("复制失败");
			});
			$("#copyLinkBtn").unbind("click");
		});
	}
	function shareFileOk(id, isshare, issearch, islimit, pwd) {
		$("#modal-button").unbind("click");
		$.ajax({
			url : "/user/file/edit",
			type : "post",
			data : JSON.stringify({
				id : id,
				isshare : isshare,
				issearch : issearch,
				islimit : islimit,
				pwd : pwd
			}),
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				if (data.code == 0) {
					$("#" + id).attr("isshare", isshare);
					$("#" + id).attr("issearch", issearch);
					$("#" + id).attr("islimit", islimit);
					$("#" + id).attr("pwd", pwd);
					isshare == 1 ? $("#status" + id).text("共享") : $("#status" + id).text("");
					showTips(null, "文件已修改！", "success");
				} else {
					showTips(null, data.msg);
				}
			},
			error : function(e) {
				showTips(null, "网络异常，请重试！", "warning");
			}
		});
		$('#exampleModal').modal('hide');
	}
	/* 预览文件 */
	function previewFile(id) {
		if ($("#preview").attr("previewId") == id) {
			return false;
		}
		$("#preview").attr("previewId", id);
		/* 无法预览 */
		var suffix = getFileSuffix($("#" + id).attr("name"));
		var uuid = $("#" + id).attr("uuid");
		var text = [ "txt", "text", "ini", "inf", "java", "php", "c", "cpp", "py", "html", "htm", "css", "js", "vbs", "jsp", "bat" ];
		var image = [ "png", "jpg", "jpeg", "bmp", "gif" ];
		var office = [ "doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf" ];
		/* 文本预览 */
		if (text.includes(suffix)) {
			$.ajax({
				url : "/file/preview/" + uuid,
				type : "get",
				contentType : "application/x-www-form-urlencoded;charset=UTF-8",
				success : function(data) {
					$("#preview-default").hide();
					$("#preview-img").hide();
					$("#preview-text").show();
					$("#preview-text").text(data);
				},
				error : function(e) {
					showTips(null, "网络异常，请重试！", "warning");
				}
			});
			return false;
		}
		/* office预览 */
		if (office.includes(suffix)) {
			$("#preview-default").show();
			$("#preview-img").hide();
			$("#preview-text").hide();
			$("#preview-default").empty();
			$("#preview-default").append("<a href='http://ow365.cn/?i=20566&furl=http://404z.cn:8080/file/download/" + uuid + "' target='_blank'>点击预览文件</a>");
			return false;
		}
		/* 图片预览 */
		if (image.includes(suffix)) {
			$("#preview-text").hide();
			$("#preview-default").hide();
			$("#preview-img").show();
			$("#preview-img").empty();
			$("#preview-img").append("<img src='/file/preview/" + uuid + "' onClick='clickImg(\"/file/preview/" + uuid + "\")'>");
			return false;
		}
		/* 无法预览 */
		$("#preview-default").show();
		$("#preview-img").hide();
		$("#preview-text").hide();
		$("#preview-default").text("文件无法预览，请下载。");
	}
	/* 点击图片全屏预览 */
	function clickImg(src) {
		var bigImgShade = '<div class="bigImgShade" style = "display:none"><img class="bigImg" src="' + src + '"></div>';
		$(document.body).append(bigImgShade);
		$(".bigImgShade").addClass("bigImgShade");
		$(".bigImgShade").show();
		$("html,body").addClass("none-scroll");
		$(".bigImg").addClass("bigImg");
		$(".bigImgShade").click(function() {
			$("html,body").removeClass("none-scroll");
			$(".bigImgShade").remove();
		});
	}
	/* 显示提示信息 */
	function showTips(name, msg, color = "danger") {
		$("#tips").remove();
		var div = "<div id=\"tips\" class=\"alert alert-dismissable alert-" + color + "\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button><span>" + msg + "</span></div>";
		$("body").prepend(div);
		$(".form-control").css("background", "#fff");
		$("#" + name).css("background", "#faa");
		$("#" + name).focus();
	}
	/*--------------------------------------------------*/
	/*--------------------------------------------------*/
	/* 加载编辑文件 */
	function loadEditFile(id, folderId, folderName) {
		$("#showFile").hide();
		$("#editFile").show();
		$("#editBtn").unbind("click");
		$.ajax({
			url : "/user/file/info/" + id,
			type : "post",
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				if (data.code == 0) {
					var d = data.data;
					$("#title").text(d.name);
					$("#name2").val(d.name);
					$("#description2").val(d.description);
					$("#length2").text(bytes2Size(d.length));
					$("#md52").text(d.md5);
					$("#time2").text(time2Date(d.time));
					$("#browsing2").text(d.browsing + "次");
					$("#download2").text(d.download + "次");
					$("#uuid2").empty();
					$("#uuid2").append("<a href='/file/download/" + d.uuid + "' target='_blank'>下载</a>");
					shareFile2(d.name, d.timestamp, d.uuid, d.isshare, d.issearch, d.islimit, d.pwd);
					$("#current-location2").empty();
					(folderId == undefined)
						? ($("#current-location2").append("当前位置：<a href='#' onClick='init()'>根目录</a> / "
							+ "<a href='#' onClick='loadEditFile(\"" + id + "\")'>" + d.name + "</a>"))
						: ($("#current-location2").append("当前位置：<a href='#' onClick='init()'>根目录</a> / "
							+ "<a href='#' onClick='init(\"" + folderId + "\",\"" + folderName + "\")'>" + folderName + "</a> / "
							+ "<a href='#' onClick='loadEditFile(\"" + id + "\",\"" + folderId + "\",\"" + folderName + "\")'>" + d.name + "</a>")) ;
					$("#reloadEdit").empty();
					(folderId == undefined)
						? ($("#reloadEdit").append("<a href='#' onClick='loadEditFile(\"" + id + "\")'>刷新页面</a>"))
						: ($("#reloadEdit").append("<a href='#' onClick='loadEditFile(\"" + id + "\",\"" + folderId + "\",\"" + folderName + "\")'>刷新页面</a>")) ;
				}
			}
		});
		$("#editBtn").click(function() {
			edit(id);
		});
	}
	/* 分享设置 */
	function shareFile2(name2, timestamp2, uuid2, isshare2, issearch2, islimit2, pwd2) {
		$("#shareCb2").unbind("click");
		$("#pwdCb2").unbind("click");
		$("#copyLinkBtn2").text("复制");
		var url = window.location.protocol + "//" + window.location.host + "/z/" + timestamp2;
		var copyLinkText = "分享文件【" + name2 + "】 下载地址: " + url;
		if (isshare2 == 1) {
			$("#shareCb2").prop("checked", true);
			$(".shareOpen2").show();
		} else {
			$("#shareCb2").prop("checked", false);
			$(".shareOpen2").hide();
		}
		if (issearch2 == 1) {
			$("#searchCb2").prop("checked", true);
		} else {
			$("#searchCb2").prop("checked", false);
		}
		if (islimit2 == 1) {
			$("#limitCb2").prop("checked", true);
		} else {
			$("#limitCb2").prop("checked", false);
		}
		if (pwd2.length != 0) {
			$("#pwdCb2").prop("checked", true);
			$("#pwdText2").text(pwd2);
			$("#linkText2").text(url + " 密码: " + pwd2);
			copyLink2(copyLinkText + " 密码: " + pwd2)
			$("#pwdOpen2").show();
		} else {
			$("#pwdCb2").prop("checked", false);
			$("#pwdOpen2").hide();
			$("#linkText2").text(url);
			copyLink2(copyLinkText)
		}
		$("#shareCb2").click(function() {
			if ($(this).is(":checked")) {
				$(".shareOpen2").show();
			} else {
				$(".shareOpen2").hide();
			}
		});
		$("#pwdCb2").click(function() {
			if ($(this).is(":checked")) {
				pwd2 = randomFilePwd();
				$("#pwdText2").text(pwd2);
				$("#linkText2").text(url + " 密码: " + pwd2);
				copyLink2(copyLinkText + " 密码: " + pwd2)
			} else {
				$("#pwdText2").text("");
				$("#linkText2").text(url);
				copyLink2(copyLinkText);
			}
		});
	}
	function copyLink2(str) {
		$("#copyLinkBtn2").click(function() {
			var clipboard = new ClipboardJS('#copyLinkBtn2', {
				text : function() {
					return str;
				}
			});
			clipboard.on('success', function(e) {
				$("#copyLinkBtn2").text("复制成功");
			});
			clipboard.on('error', function(e) {
				$("#copyLinkBtn2").text("复制失败");
			});
			$("#copyLinkBtn2").unbind("click");
		});
	} /* 编辑 */
	function edit(id) {
		var name2 = $("#name2").val();
		var description2 = $("#description2").val();
		var isshare2 = $("#shareCb2").is(":checked") == true ? 1 : 0;
		var issearch2 = $("#searchCb2").is(":checked") == true ? 1 : 0;
		var islimit2 = $("#limitCb2").is(":checked") == true ? 1 : 0;
		var pwd2 = $("#pwdText2").text();
		console.log(isshare2, issearch2, islimit2, pwd2);
		if (name2.length == 0) {
			showTips("name2", "文件名不可为空！");
			return false;
		}
		$.ajax({
			url : "/user/file/edit",
			type : "post",
			data : JSON.stringify({
				id : id,
				name : name2,
				description : description2,
				isshare : isshare2,
				issearch : issearch2,
				islimit : islimit2,
				pwd : pwd2
			}),
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				if (data.code == 0) {
					$("#title").text(name2);
					showTips(null, "修改成功！", "success");
				} else {
					showTips(null, data.msg);
				}
			},
			error : function(e) {
				showTips(null, "网络异常，请重试！", "warning");
			}
		});
	}
</script>
</head>
<body>
	<div id="title">我的文件</div>
	<!-- 显示文件列表 -->
	<div id="showFile">
		<!-- 功能区开始 -->
		<div class="col-left">
			<span id="current-location">&emsp;</span>
			<!-- <span id="current-page">&emsp;</span> -->
			<div id="operation">
				<button class="btn btn-success" onClick="uploadFile()">上传文件</button>
				<button class="btn btn-default" onClick="newFolder()" id="newFolder">新建文件夹</button>
				<button class="btn btn-primary" onClick="downloadPackage()">打包下载</button>
				<!-- 			<button class="btn btn-info" onClick="copyFile()">复制</button> -->
				<!-- 			<button class="btn btn-warning" onClick="cutFile()">剪切</button> -->
				<!-- 			<button class="btn btn-success" onClick="pasteFile()">粘贴</button> -->
				<button class="btn btn-danger" onClick="deleteFile()">删除</button>
			</div>
		</div>
		<div class="col-right">
			<span id="current-operation">&emsp;</span>
		</div>
		<!-- 功能区结束 -->
		<!-- 文件列表开始 -->
		<div class="col-left">
			<table class="table table-hover table-striped table-condensed">
				<thead>
					<tr>
						<th style="width: 1em;">
							<input type="checkbox" id="selectAll">
						</th>
						<th>文件名</th>
						<th style="width: 9em;"></th>
						<th style="width: 6em;">文件大小</th>
						<th style="width: 4em;">状态</th>
						<th style="width: 11em;">上传时间</th>
					</tr>
				</thead>
				<tbody id="fileList"></tbody>
			</table>
		</div>
		<!-- 文件列表结束 -->
		<!-- 预览开始 -->
		<div class="col-right" id="preview">
			<div id="preview-default">暂无预览内容</div>
			<div id="preview-img"></div>
			<pre id="preview-text"></pre>
		</div>
		<!-- 预览结束 -->
		<!-- 模态框开始 -->
		<div class="modal fade" id="exampleModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<!-- 头部标题和关闭按钮 -->
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">
							<span aria-hidden="true">×</span>
						</button>
						<h4 class="modal-title" id="modal-title"></h4>
					</div>
					<div class="modal-body" id="modal-body">
						<!-- 删除div-->
						<div id="deleteDiv">
							<h5>确定要删除吗？</h5>
						</div>
						<!-- 新建文件夹div-->
						<div id="newFolderDiv">
							<input type="text" class="form-control" placeholder="请输入文件夹名" id="newFolderName">
						</div>
						<!--重命名div-->
						<div id="renameDiv">
							<input type="text" class="form-control" placeholder="请输入文件/文件夹名" id="newName">
						</div>
						<!--分享div-->
						<table id="shareDiv">
							<tr>
								<td class="text">分享</td>
								<td style="width: 2em;">
									<input type="checkbox" id="shareCb" />
								</td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr class="shareOpen">
								<td class="text">可搜索到</td>
								<td>
									<input type="checkbox" id="searchCb" />
								</td>
								<td></td>
								<td class="text">需要登录</td>
								<td style="width: 12em;">
									<input type="checkbox" id="limitCb" />
								</td>
								<td></td>
							</tr>
							<tr class="shareOpen">
								<td class="text">密码</td>
								<td>
									<input type="checkbox" id="pwdCb" />
								</td>
								<td style="width: 6em;">
									<label class="form-control" id="pwdText"></label>
								</td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr class="shareOpen">
								<td class="text">分享链接</td>
								<td></td>
								<td colspan="3">
									<label class="form-control" id="linkText"></label>
								</td>
								<td style="padding-left:0.5em;width:8em;">
									<button class="btn btn-info" id="copyLinkBtn">复制</button>
								</td>
							</tr>
						</table>
					</div>
					<!-- 底部按钮 -->
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-success" id="modal-button">确定</button>
					</div>
				</div>
			</div>
		</div>
		<!-- 模态框结束 -->
	</div>
	<!-- 编辑文件 -->
	<div id="editFile">
		<span id="current-location2">&emsp;</span>
		<table>
			<tr>
				<td class="text">文件名</td>
				<td></td>
				<td colspan="4" class="input">
					<input type="text" class="form-control" placeholder="请输入文件名" id="name2" />
				</td>
				<td></td>
			</tr>
			<tr>
				<td class="text">文件描述</td>
				<td></td>
				<td colspan="4" class="input">
					<textarea rows="5" class="form-control" placeholder="请输入文件描述" id="description2"></textarea>
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="width: 8em;" class="text">文件大小</td>
				<td></td>
				<td style="width: 6em;" class="input">
					<label class="form-control" id="length2"></label>
				</td>
				<td style="width: 10em;" class="text">文件下载地址</td>
				<td style="width: 2em;"></td>
				<td style="width: 6em;" class="input">
					<label class="form-control" id="uuid2"></label>
				</td>
				<td style="width: 10em;" class="prompt">提示：不可修改。</td>
			</tr>
			<tr>
				<td class="text">文件浏览次数</td>
				<td></td>
				<td class="input">
					<label class="form-control" id="browsing2"></label>
				</td>
				<td class="text">文件下载次数</td>
				<td></td>
				<td class="input">
					<label class="form-control" id="download2"></label>
				</td>
				<td class="prompt">提示：不可修改。</td>
			</tr>
			<tr>
				<td class="text">文件MD5</td>
				<td></td>
				<td colspan="4" class="input">
					<label class="form-control" id="md52"></label>
				</td>
				<td class="prompt">提示：不可修改。</td>
			</tr>
			<tr>
				<td class="text">文件上传时间</td>
				<td></td>
				<td colspan="4" class="input">
					<label class="form-control" id="time2"></label>
				</td>
				<td class="prompt">提示：不可修改。</td>
			</tr>
			<tr>
				<td class="text">分享</td>
				<td style="width: 2em;" class="input">
					<input type="checkbox" id="shareCb2" />
				</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr class="shareOpen2">
				<td class="text">可搜索到</td>
				<td class="input">
					<input type="checkbox" id="searchCb2" />
				</td>
				<td></td>
				<td class="text">需要登录</td>
				<td class="input">
					<input type="checkbox" id="limitCb2" />
				</td>
				<td></td>
				<td></td>
			</tr>
			<tr class="shareOpen2">
				<td class="text">密码</td>
				<td class="input">
					<input type="checkbox" id="pwdCb2" />
				</td>
				<td class="input">
					<label class="form-control" id="pwdText2"></label>
				</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td class="text">分享链接</td>
				<td></td>
				<td colspan="4" class="input">
					<label class="form-control" id="linkText2"></label>
				</td>
				<td style="padding-left:0.5em;">
					<button class="btn btn-info" id="copyLinkBtn2">复制</button>
				</td>
			</tr>
			<tr>
				<td class="link" id="reloadEdit"></td>
				<td></td>
				<td colspan="4">
					<button class="btn btn-success btn-lg" id="editBtn">修改信息</button>
				</td>
				<td></td>
			</tr>
		</table>
	</div>
</body>
</html>
